<script setup>
import { h, onMounted, ref,computed, resolveDirective, withDirectives } from 'vue'
import {
  NButton,
  NCheckbox,
  NCheckboxGroup,
  NForm,
  NFormItem,
  NImage,
  NInput,
  NSpace,
  NSwitch,
  NTag,
  NPopconfirm,
  NLayout,
  NLayoutSider,
  NLayoutContent,
  NTreeSelect,
  useMessage,
  NFlex,
  NAvatar, NSelect, NInputNumber
} from 'naive-ui'


import api from "@/api";
import { usePermissionStore, useAppStore } from '@/store'
import { renderCustomIcon, renderIcon, isExternal } from '@/utils'

import FullScreen from '@/layout/components/header/components/FullScreen.vue'
import UserAvatar from '@/layout/components/header/components/UserAvatar.vue'
import Languages from "@/layout/components/header/components/Languages.vue";

const router = useRouter()
const curRoute = useRoute()
const permissionStore = usePermissionStore()
const appStore = useAppStore()

const props = defineProps({
  infoData: {
    type: Object,
    required: true
  }
});


const data = reactive({
  parent_id:0,
  menus:[],
  menu_now:{}
});


onMounted(() => {
  data.parent_id = props.infoData.id
  get_menus()
})

function get_menus(){
  api.getMenusByPid({
    parent_id:data.parent_id
  }).then((res) => {
    data.menus = res.data.res_menu
    data.menu_now = res.data.first_menu
  })
}

function select_menu(item,item2) {
  router.push(data.menu_now.path+"/"+item.path+"/"+item2.path)
}

</script>

<template>
  <AppPage :show-footer="false" >
    <div class="app_page">
      <div class="row" v-for="item in data.menus">
        <n-card :bordered="false" hoverable content-style="padding: 0px;" :segmented="{
          content: true,
          footer: 'soft',
        }">
          <template #header><n-h6 prefix="bar" style="margin: 0;font-size: 18px">{{item.name}}</n-h6></template>
          <template #footer>
            <div style="display: flex">

              <div class="item1" v-for="item2 in item.children" @click="select_menu(item,item2)">
                <div class="icon">
                  <component :is="renderIcon(item2.icon, { size: 35,color:'#fff' })" />
                </div>
                <div class="text">{{item2.name}}</div>
              </div>

            </div>
          </template>
        </n-card>
      </div>


    </div>


  </AppPage>
</template>

<style scoped>
.header{
  width: 100%;
  height: 65px;
  line-height: 65px;
  background: #fff;
  color:#000;
  text-align: center;
  font-size: 20px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  position: fixed;
  top:0;
  z-index: 1;
}
.app_page{
  margin-top:0px;
}
.row{
  width: 100%;
  margin-bottom: 20px;
}
.item1{
  width: 100px;
  text-align: center;
  cursor:pointer;
  img{
    width: 70px;
  }
}
.icon{
  //background: #8945c3;
  width: 70px;
  height: 70px;
  line-height: 90px;
  border-radius: 10px;
  margin: 0 auto;
  background: linear-gradient(180deg, #c87373 10%, #67367e 100%);
  //background: linear-gradient(180deg, #a59aca 10%, #5f479a 100%);
}
.text{
  margin-top: 10px;
  font-size: 16px;
}
</style>